﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Module;
using System.Data.SqlClient;
using System.Data;
using Qmaker.DAL;

namespace DLL
{
    public class DUserProfileEnumInfo
    {
        #region SQL语句

        #region 查询

        private const string SQL_SELECT = "select UserProfileEnumId,ProfileName,Label,Value,ParentUserProfileEnumId,IsDelete from UserProfileEnum where ProfileName=@ProfileName";

        #endregion

        #endregion

        #region 公共接口

        /// <summary>
        /// 根据用户ProfileName获取所有的枚举值
        /// </summary>
        /// <returns></returns>
        public List<UserProfileEnumInfo> GetProfileEnumByProfileName(string profileName)
        {
            List<UserProfileEnumInfo> result = new List<UserProfileEnumInfo>();
            SqlParameter[] parms = {
                    new SqlParameter("@ProfileName",SqlDbType.BigInt)
                };
            parms[0].Value = profileName;
            UserProfileEnumInfo profileEnum = null;
            using (SqlDataReader reader = SqlHelper.ExecuteReader(SqlHelper.ConnectionString, CommandType.Text, SQL_SELECT, parms))
            {
                while (reader.Read())
                {
                    profileEnum = GetInstanceByDataReader(reader);
                    if (profileEnum != null)
                        result.Add(profileEnum);
                }
            }
            return result;
        }

        private UserProfileEnumInfo GetInstanceByDataReader(SqlDataReader reader)
        {
            //UserProfileEnumId,ProfileName,Label,Value,ParentUserProfileEnumId,IsDelete
            UserProfileEnumInfo current = new UserProfileEnumInfo();
            current.UserProfileEnumId = reader.IsDBNull(0) ? 0 : reader.GetInt64(0);
            current.ProfileName = reader.IsDBNull(1) ? string.Empty : reader.GetString(1);
            current.Label = reader.IsDBNull(2) ? string.Empty : reader.GetString(2);
            current.Value = reader.IsDBNull(3) ? 0 : reader.GetInt32(3);
            current.ParentUserProfileEnumId = reader.IsDBNull(4) ? 0 : reader.GetInt64(4);
            current.IsDelete = reader.IsDBNull(5) ? 0 : reader.GetInt32(5);

            return current;
        }







        #endregion
    }
}
